<?php

class Core_Component_System_Controller_Backend_Website {
    
    public function __construct() {
        $GLOBALS[RC]->getHelper()->setLocation('{system.system}', '{system.website}');
    }
    
    public function mappingAction(){
        return array(
            'create'=>'edit'
        );
    }

    public function indexAction($pageindex = 1, $pagesize = 20){
        $q = App::getModel('system/website')->getQuery();
        $list = $q->pagination($pageindex, $pagesize)->fetch();
        $count = $q->fetchCount();
        return $GLOBALS[RC]->getHelper()->templateResult(array('list'=>$list, 'record_count'=>$count));
    }
    
    public function editAction($id = NULL){
        $cultures = App::getModel('system/localize')->getQuery()->fetch();
        $model = App::getModel('system/website');
        if(!is_null($id)){
            $model->load($id);
            $GLOBALS[RC]->getHelper()->setLocation($model->getName());
        }else{
            $GLOBALS[RC]->getHelper()->setLocation('{system.new_website}');
        }
        return $GLOBALS[RC]->getHelper()->modelFormResult($model,
                array('lang'=>array('data'=>$cultures, 'labelKey'=>'lang_name', 'valueKey'=>'lang_code')),
                '*/*/edit');
    }    
    
    public function saveAction(Core_Component_System_Model_Website $model){
        $model->merge()->validate()->save();
        $GLOBALS[RC]->getMessager()->addInformation('{system.message.success}');
        return $GLOBALS[RC]->getHelper()->historyResult('*/*/*/index');
    }    
    
    public function forbidPostAction($ids){
        App::getBusiness('system/website')->modifyWebsiteStatus($ids, CONSTANT_STATUS_FORBIDDEN);
        return $GLOBALS[RC]->getHelper()->historyResult('*/*/*/index');
    }  
    
    public function defaultAction($id){
        App::getBusiness('system/website')->setDefaultWebsite($id);
        return $GLOBALS[RC]->getHelper()->historyResult('*/*/*/index');
    }
}